//
//  jquery.lt_dialog.js
//  jq plugin
//
//  Created by sang alfred on 20/10/2013.
//
//

;(function($) {   
	 
	var bPass = true;

	 //--------------------- public methods --------------------------
    function pp(info){

		if (window.console && window.console.log)    
			window.console.log('LOG: ' + info ); 

    };

    //--------------------- dialog显示动画开始 --------------------------
	function dialog_show_animate(obj,opts){
			var styleLatter = obj.show().css({
				'width':opts.width,
				'height':opts.height,
				'z-index':'1000',
				'position':'absolute',
				'left':'100%'
			});
			if(opts.doTime){
				$(styleLatter).stop().animate({
					left:'0%',
					width:'100%'
				},opts.speed,function(){
					bPass = true;
				});
				opts.load_callback(obj);
			}else{
				styleLatter.stop().animate({
					left:'0%',
					width:'100%'
				},opts.speed,function(){
					opts.load_callback(obj);
					bPass = true;
				});
			};

	};
	//--------------------- dialog显示动画结束 --------------------------

	//--------------------- dialog消失动画开始 --------------------------
	function dialog_close_animate(obj,opts){
			obj.prepend($('<div class="close_dialog"><input class="close_dialog_btn" type="button" value="隐藏"></div>'));
			$('.close_dialog').click(function(){
				 $(obj).stop().animate({
					left:'100%',
					width:'0%'
				},opts.speed,function(){
				    $(obj).css({
						'display':'none'
				    });	
				});	
				$('.close_dialog_btn').remove();
            }); 

	};
	//--------------------- dialog消失动画结束 --------------------------

	

    //----------------------- jquery   plugin  -----------------------
	$.fn.lt_dialog = function(options) {  
        // init var
		var opts = $.extend({}, $.fn.lt_dialog.defaults, options);
		if(bPass){
			bPass = false;
			//start plugin here
			return this.each(function() { 
				$this = $(this);

				//让dialog显示，实现动画效果
				dialog_show_animate($this,opts);
				
				//创建关闭按钮，让dialog隐藏，实现动画效果
				dialog_close_animate($this,opts);

			});//end this.each 

		};

	};
    //插件的defaults    
	$.fn.lt_dialog.defaults = {
		doTime:false,
		speed:200,
		width:100,
		height:'100%',
		load_callback:function(obj){ 
		}
    };
})(jQuery);
